package org.example.afiona.service.impl;

import org.example.afiona.custom.Producer;
import org.example.afiona.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

@EnableBinding(Producer.class) // 可以理解为是一个消息的发送管道的定义
public class MessageProviderImpl implements IMessageProvider
{
    @Resource
    private MessageChannel producer; // 消息的发送管道

    @Override
    public String send()
    {
        this.producer.send(MessageBuilder.withPayload("hello，springcloud").build()); // 创建并发送消息

        return "";
    }
}